<template>
  <div class="body">
    <!-- 顶部4个card部分 -->
    <el-row class="oneRow" :gutter="10">
      <!-- card部分，分别为1234图 -->
      <el-col :span="6">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <div class="one">
              <span>总销售额</span>
              <svg
                t="1656300537431"
                class="icon"
                viewBox="0 0 1024 1024"
                version="1.1"
                xmlns="http://www.w3.org/2000/svg"
                p-id="5358"
                width="16"
                height="16"
              >
                <path
                  d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64z m0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"
                  p-id="5359"
                  fill="#8a8a8a"
                ></path>
                <path
                  d="M512 336m-48 0a48 48 0 1 0 96 0 48 48 0 1 0-96 0Z"
                  p-id="5360"
                  fill="#8a8a8a"
                ></path>
                <path
                  d="M536 448h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V456c0-4.4-3.6-8-8-8z"
                  p-id="5361"
                  fill="#8a8a8a"
                ></path>
              </svg>
            </div>
            <div class="title">￥12345</div>
            <div class="upIcon">
              <pre>周同比  56.7%</pre>
              <svg
                t="1656559530581"
                class="icon"
                viewBox="0 0 1024 1024"
                version="1.1"
                xmlns="http://www.w3.org/2000/svg"
                p-id="5320"
                width="16"
                height="16"
              >
                <path
                  d="M960 704L512 256l-448 448z"
                  fill="#1afa29"
                  p-id="5321"
                ></path>
              </svg>
            </div>
            <pre>日同比  17.6%</pre>
            <svg
              t="1656559597691"
              class="icon"
              viewBox="0 0 1024 1024"
              version="1.1"
              xmlns="http://www.w3.org/2000/svg"
              p-id="6314"
              width="16"
              height="16"
            >
              <path
                d="M64 320l448 448 448-448z"
                fill="#d81e06"
                p-id="6315"
              ></path>
            </svg>
          </div>
          <div>日销售额</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <div class="one">
              <span>访问量</span>
              <svg
                t="1656300537431"
                class="icon"
                viewBox="0 0 1024 1024"
                version="1.1"
                xmlns="http://www.w3.org/2000/svg"
                p-id="5358"
                width="16"
                height="16"
              >
                <path
                  d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64z m0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"
                  p-id="5359"
                  fill="#8a8a8a"
                ></path>
                <path
                  d="M512 336m-48 0a48 48 0 1 0 96 0 48 48 0 1 0-96 0Z"
                  p-id="5360"
                  fill="#8a8a8a"
                ></path>
                <path
                  d="M536 448h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V456c0-4.4-3.6-8-8-8z"
                  p-id="5361"
                  fill="#8a8a8a"
                ></path>
              </svg>
            </div>
            <div class="title">12345</div>
            <div ref="line" style="width: 100%; height: 50px"></div>
          </div>
          <div>日访问量 12345</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <div class="one">
              <span>支付笔数</span>
              <svg
                t="1656300537431"
                class="icon"
                viewBox="0 0 1024 1024"
                version="1.1"
                xmlns="http://www.w3.org/2000/svg"
                p-id="5358"
                width="16"
                height="16"
              >
                <path
                  d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64z m0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"
                  p-id="5359"
                  fill="#8a8a8a"
                ></path>
                <path
                  d="M512 336m-48 0a48 48 0 1 0 96 0 48 48 0 1 0-96 0Z"
                  p-id="5360"
                  fill="#8a8a8a"
                ></path>
                <path
                  d="M536 448h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V456c0-4.4-3.6-8-8-8z"
                  p-id="5361"
                  fill="#8a8a8a"
                ></path>
              </svg>
            </div>
            <div class="title">12345</div>
            <div ref="bar" style="width: 100%; height: 50px"></div>
          </div>
          <div>转化率 65%</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <div class="one">
              <span>运营活动效果</span>
              <svg
                t="1656300537431"
                class="icon"
                viewBox="0 0 1024 1024"
                version="1.1"
                xmlns="http://www.w3.org/2000/svg"
                p-id="5358"
                width="16"
                height="16"
              >
                <path
                  d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64z m0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"
                  p-id="5359"
                  fill="#8a8a8a"
                ></path>
                <path
                  d="M512 336m-48 0a48 48 0 1 0 96 0 48 48 0 1 0-96 0Z"
                  p-id="5360"
                  fill="#8a8a8a"
                ></path>
                <path
                  d="M536 448h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V456c0-4.4-3.6-8-8-8z"
                  p-id="5361"
                  fill="#8a8a8a"
                ></path>
              </svg>
            </div>
            <div class="title">75%</div>
            <div ref="yBar" style="width: 100%; height: 50px"></div>
          </div>
          <div>日销售额</div>
        </el-card>
      </el-col>
    </el-row>
    <!-- 下方统计图 -->
    <el-card style="margin-top: 20px">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="销售额" name="first"></el-tab-pane>
        <el-tab-pane label="访问量" name="second"></el-tab-pane>
      </el-tabs>
      <el-row :gutter="60">
        <el-col :span="17">
          <div ref="saleBar" style="width: 100%; height: 400px"></div>
        </el-col>
        <el-col :span="7">
          <!-- 门店销售额排名 -->
          <h3 class="rank">门店销售额排名</h3>
          <ul class="saleRank">
            <li>
              <span>1</span>
              <span>肯德基</span>
              <span>123456</span>
            </li>
            <li>
              <span>2</span>
              <span>麦当劳</span>
              <span>123456</span>
            </li>
            <li>
              <span>3</span>
              <span>汉堡王</span>
              <span>123456</span>
            </li>
            <li>
              <span>4</span>
              <span>黄焖鸡</span>
              <span>123456</span>
            </li>
            <li>
              <span>5</span>
              <span>校堡王</span></span>
              <span>123456</span>
            </li>
            <li>
              <span>6</span>
              <span>正新鸡排</span>
              <span>123456</span>
            </li>
            <li>
              <span>7</span>
              <span>周黑鸭</span></span></span>
              <span>123456</span>
            </li>
          </ul>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<script>
import * as echarts from "echarts";
export default {
  name: "Dashboard",
  data() {
    return {
      activeName: "first",
      line: "",
      bar: "",
      yBar: "",
      saleBar: "",
      lineOption: "",
      barOption: "",
      yBarOption: "",
      saleBarOption: "",
    };
  },
  methods: {
    // tabs点击事件
    handleClick(tab) {
      if (tab.index == 0) {
        this.saleBar.setOption({
          title: {
            text: "销售额趋势",
          },
          series: [
            {
              type: "bar",
              data: [
                200, 300, 100, 200, 300, 500, 300, 300, 200, 300, 100, 600,
              ],
              color: "green",
            },
          ],
        });
      }
      if (tab.index == 1) {
        this.saleBar.setOption({
          title: {
            text: "访问量趋势",
          },
          series: [
            {
              type: "bar",
              data: [
                100, 200, 100, 200, 300, 100, 300, 300, 200, 100, 100, 600,
              ],
              color: "orange",
            },
          ],
        });
      }
    },
  },
  mounted() {
    this.line = echarts.init(this.$refs.line);
    this.bar = echarts.init(this.$refs.bar);
    this.yBar = echarts.init(this.$refs.yBar);
    this.saleBar = echarts.init(this.$refs.saleBar);
    this.lineOption = {
      xAxis: {
        type: "category",
        show: false,
        boundaryGap: false,
      },
      yAxis: {
        show: false,
      },
      grid: {
        left: 0,
        right: 0,
        buttom: 0,
      },
      legend: {},
      series: [
        {
          type: "line",
          data: [5, 7, 10, 5, 10, 6, 13],
          smooth: true,
          lineStyle: {
            color: "red",
          },
          areaStyle: {
            color: {
              type: "linear",
              x: 0,
              y: 0,
              x2: 0,
              y2: 1,
              colorStops: [
                {
                  offset: 0,
                  color: "red", // 0% 处的颜色
                },
                {
                  offset: 1,
                  color: "green", // 100% 处的颜色
                },
              ],
              global: false, // 缺省为 false
            },
          },
          itemStyle: {
            opacity: 0,
          },
        },
      ],
    };
    this.barOption = {
      xAxis: {
        show: false,
        type: "category",
        boundaryGap: false,
      },
      yAxis: {
        show: false,
      },
      grid: {
        left: 0,
      },
      series: {
        type: "bar",
        data: [23, 45, 30, 56, 50, 33, 45, 67, 83],
      },
    };
    this.yBarOption = {
      xAxis: {
        show: false,
        min: 0,
        max: 100,
      },
      yAxis: {
        show: false,
        type: "category",
        // boundaryGap: false,
      },
      grid: {
        left: 0,
      },
      series: {
        type: "bar",
        data: [75],
        showBackground: true,
        backgroundStyle: {
          color: "#eee",
        },
        label: {
          show: true,
          formatter: "|",
          position: "right",
          color: "green",
          fontSize: "14px",
        },
        barWidth: 10,
        color: "cyan",
      },
    };
    this.saleBarOption = {
      // title: "销售额趋势",
      title: {
        text: "销售额趋势",
      },
      grid: {
        left: 50,
        top: 50,
        right: 0,
        bottom: 50,
      },
      xAxis: {
        data: [
          "一月",
          "二月",
          "三月",
          "四月",
          "五月",
          "六月",
          "七月",
          "八月",
          "九月",
          "十月",
          "十一月",
          "十二月",
        ],
      },
      yAxis: {
        axisLine: {
          show: true,
        },
        axisTick: {
          show: true,
        },
      },
      series: [
        {
          type: "bar",
          data: [200, 300, 100, 200, 300, 500, 300, 300, 200, 300, 100, 600],
        },
      ],
    };
    this.line.setOption(this.lineOption);
    this.bar.setOption(this.barOption);
    this.yBar.setOption(this.yBarOption);
    this.saleBar.setOption(this.saleBarOption);
  },
};
</script>


<style scoped>
h3.rank{
  line-height: 50px;
}
* {
  padding: 0;
  margin: 0;
  list-style: none;
}
.saleRank li {
  line-height: 20px;
  padding: 13px 0;
}
/* 排名数字样式 */
.saleRank li span:first-child {
  float: left;
  width: 20px;
  line-height: 20px;
  text-align: center;
  margin-right: 20px;
}
/* 前三个数字样式 */
.saleRank li:nth-child(-n + 3) span:first-child {
  border-radius: 50%;
  background-color: black;
  color: white;
}
.saleRank li span:last-child {
  color: red;
  float: right;
  margin-right: 30px;
}
.body {
  box-sizing: border-box;
  height: 400px;
}
.oneRow >>> .el-card__header {
  padding-bottom: 0;
}
.oneRow >>> .el-card__header:first-child {
  height: 111px;
}
.oneRow >>> .el-card__body {
  line-height: 40px;
  padding: 0 20px;
}
.one {
  display: flex;
  justify-content: space-between;
  color: #c9c9c9;
  font-size: 12px;
}
.title {
  font-size: 23px;
}
pre {
  display: inline;
  font-size: 14px;
}
.upIcon {
  display: inline;
  margin-right: 30px;
}
</style>
